package com.lst.api.vo;

import com.lst.api.constant.MaritalStatusEnum;
import com.lst.api.constant.RegexEnum;
import com.lst.api.entity.PersonInfo;
import com.lst.api.exception.RequestParamErrorException;
import com.lst.tools.basics.utils.RegexUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 借款人个人信息表
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class PersonInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "name", value = "姓名", required = true, dataType = "String")
    private String name;

    @ApiModelProperty(name = "nativeProvinceCode", value = "籍贯，省编号", required = true, dataType = "String")
    private String nativeProvinceCode;

    @ApiModelProperty(name = "nativeCityCode", value = "籍贯，市编号", required = true, dataType = "String")
    private String nativeCityCode;

    @ApiModelProperty(name = "mobile", value = "手机号", required = true, dataType = "String")
    private String mobile;

    @ApiModelProperty(name = "maritalStatus", value = "婚姻状况    1:已婚    2:未婚   3:其他", required = true, dataType = "String")
    private String maritalStatus;

    @ApiModelProperty(name = "idCardNo", value = "身份证号", required = true, dataType = "String")
    private String idCardNo;

    @ApiModelProperty(name = "resideAddressProvinceCode", value = "居住地址，省编号", required = true, dataType = "String")
    private String resideAddressProvinceCode;

    @ApiModelProperty(name = "resideAddressCityCode", value = "居住地址，市编号", required = true, dataType = "String")
    private String resideAddressCityCode;

    @ApiModelProperty(name = "resideAddressAreaCode", value = "居住地址，区编号", required = true, dataType = "String")
    private String resideAddressAreaCode;

    @ApiModelProperty(name = "resideAddressDetails", value = "居住地址，详细地址", required = true, dataType = "String")
    private String resideAddressDetails;

    @ApiModelProperty(name = "resideTypeId", value = "居住类型id", required = true, dataType = "Long")
    private Long resideTypeId;

    public PersonInfoVo(PersonInfo personInfo) {
        if (personInfo == null) {
            return;
        }
        this.name = personInfo.getName();
        this.nativeProvinceCode = personInfo.getNativeProvinceCode();
        this.nativeCityCode = personInfo.getNativeCityCode();
        this.mobile = personInfo.getMobile();
        this.maritalStatus = personInfo.getMaritalStatus();
        this.idCardNo = personInfo.getIdCardNo();
        this.resideAddressProvinceCode = personInfo.getResideAddressProvinceCode();
        this.resideAddressCityCode = personInfo.getResideAddressCityCode();
        this.resideAddressAreaCode = personInfo.getResideAddressAreaCode();
        this.resideAddressDetails = personInfo.getResideAddressDetails();
        this.resideTypeId = personInfo.getResideTypeId();
    }

    public void check() {
        boolean check = StringUtils.isNotBlank(this.name)
                && StringUtils.isNotBlank(this.nativeProvinceCode)
                && StringUtils.isNotBlank(this.nativeCityCode)
                && RegexUtils.match(RegexEnum.MOBILE.getRegex(), this.mobile)
                && MaritalStatusEnum.getByKey(this.maritalStatus) != null
                && RegexUtils.match(RegexEnum.ID_CARD_NO.getRegex(), this.idCardNo)
                && StringUtils.isNotBlank(this.resideAddressProvinceCode)
                && StringUtils.isNotBlank(this.resideAddressCityCode)
                && StringUtils.isNotBlank(this.resideAddressAreaCode)
                && StringUtils.isNotBlank(this.resideAddressDetails)
                && this.resideTypeId != null;
        if (!check) {
            throw new RequestParamErrorException("PersonInfoVo请求参数不合法！");
        }
    }
}